'use strict';
const Controller = require('egg').Controller;

class AppController extends Controller {

  async index() {
    const { ctx } = this;
    const date = new Date();

    date.setHours(0);
    date.setMinutes(0);
    date.setSeconds(0);

    await ctx.model.Tongji.record(ctx);
    const countor = {
      all: await ctx.model.Tongji.countDocuments(),
      today: await ctx.model.Tongji.countDocuments({ createdAt: { $gt: date } }),
    };

    console.info(countor);
    await ctx.render('app.js', { url: ctx.url, countor });
  }
}

module.exports = AppController;
